import random
from math import trunc

import pyautogui
import time
import threading

def get_mouse_position():
    try:
        x,y = pyautogui.position()
        print(f"当前鼠标位置：（{x},{y})")
        return x,y
    except Exception as e:
        print(f"获取鼠标位置失败：{e}")
        return None, None

def click_mouse(position, click_count=1, interval=1):
    try:
        for i in range(click_count):
            pyautogui.click(x=position[0],y=position[1])
            print(f"已点击 {i+1} 次")
            time.sleep(interval)
        print("点击结束")
    except Exception as e:
        print(f"点击失败：{e}")

def main():
    print("自动化点击鼠标")

    x,y = get_mouse_position()
    # if x is None or y is None:
    #     print("ERROR")
    #     return
    # try:
    #     click_count = int(input("请输入："))
    #     interval = float(input("请输入(s)："))
    # except ValueError:
    #     print("ERROR")
    #     return
    #
    # click_mouse((x,y),click_count,interval)

if __name__== "__main__":

    while True:
        main()
        time.sleep(1)
    # while True:
    #     get_mouse_position()
    #     time.sleep(1)
